<?
	include('top.php');
	include('conn.php');

	session_start();
	$msg='';
	if($_REQUEST['up']=='true' and isset($_REQUEST['id']))
	{
		$id=$_REQUEST['id'];
		$sqledit="select * from transactionmast where trnid=$id";
		$resedit=mysql_query($sqledit);
		$rowedit=mysql_fetch_assoc($resedit);		
		$date=$rowedit['trndate'];
		$year= substr($date,0,4);
		$month = substr($date,5,2);
		$day = substr($date,8,2);
		$dateist = $day.'-'.$month.'-'.$year;
		$paydate=$rowedit['paydate'];
		if (strlen(trim($paydate))<>0)
		{
		$year= substr($paydate,0,4);
		$month = substr($paydate,5,2);
		$day = substr($paydate,8,2);
		$paydate = $day.'-'.$month.'-'.$year;
		}
		else
		{
			$paydate = '';
		}$payid=$rowcust['payid'];
//		$year= substr($paydate,0,4);
//		$month = substr($paydate,5,2);
//		$day = substr($paydate,8,2);
//		$paydate = $day.'-'.$month.'-'.$year;
		$custid = $rowedit['custid'];
		$sqlcust="select * from customermast where custid=$custid";
		$rescust=mysql_query($sqlcust);
		$rowcust=mysql_fetch_assoc($rescust);		
		$custdesc = $rowcust['custdesc'];		
	}
	if($_REQUEST['submit']=='Update')
	{

		$trnid=$_REQUEST['trnid'];
//		$trndate=$_REQUEST['datepicker3'];
		$date=$_REQUEST['datepicker3'];
		$day= substr($date,0,2);
		$month = substr($date,3,2);
		$year = substr($date,6,4);
		$trndate=$year.'-'.$month.'-'.$day;
		$bid=$_REQUEST['bid'];
		$catid=$_REQUEST['catid'];
		$custid=$_REQUEST['custid'];
		$subid=$_REQUEST['sid'];
        $venid=$_REQUEST['venid'];
		$debitamt=$_REQUEST['dramount'];
		$creditamt=$_REQUEST['cramount'];
        $netrate=$_REQUEST['netrate'];
//		$balamt=$_REQUEST['balamount'];
		$remarks=$_REQUEST['remarks'];
		$payid=$_REQUEST['payid'];
		$bankid=$_REQUEST['bankid'];
		$branchname=$_REQUEST['branch'];
//		$paydate=$_REQUEST['paydate'];
		$paydate=$_REQUEST['paydate'];
		if (strlen($paydate)<>0)
		{
		$day= substr($paydate,0,2);
		$month = substr($paydate,3,2);
		$year = substr($paydate,6,4);
		$paydate=$year.'-'.$month.'-'.$day;
		}
		else
		{
			$paydate = '';
		}

//		$datepay=$_REQUEST['paydate'];
//		$day= substr($datepay,0,2);
//		$month = substr($datepay,3,2);
//		$year = substr($datepay,6,4);
//		$paydate=$year.'-'.$month.'-'.$day;
		$payamt=$_REQUEST['amount'];
		$enteredby=$_SESSION['username'];
		$custid=str_replace('c',"",$custid);
		$custid=str_replace('d',"",$custid);
		$custid=str_replace('i',"",$custid);
        $custid=str_replace('r',"",$custid);
        $custid=str_replace('v',"",$custid);
		$idnumber=$_REQUEST['idnumber'];
	//	echo $custid;

echo $rowc;

		// if ($payid==1)
		 // $bankid=1;
		if ($subid==0)
			$subid=1;	
		
		$sql="update transactionmast set trndate='".$trndate."',bid='".$bid."',catid='".$catid."',custid='".$custid."',subid='".$subid."',venid='".$venid."',debitamt='".$debitamt."',
				creditamt='".$creditamt."',netrate='".$netrate."',remarks='".$remarks."',payid='".$payid."',bankid='".$bankid."',branchname='".$branchname."',paydate='".$paydate."',payamt='".$payamt."',modifiedby='".$enteredby."',modifieddt=sysdate(),"."idnumber='".$idnumber."' where trnid=$trnid";
		$res=mysql_query($sql);
		if($res)
		{
			 echo "<script>window.location.href = 'griddata.php'</script>";
		}	
		else
		{
			$msg='';			
		}
	}	
?>
 <script type="text/javascript" src="main.js"></script>
 <script language="javascript">
       $(function() {
               $("#datepicker3").datepicker({ dateFormat: "dd-mm-yy" }).val();
               $("#paydate").datepicker({ dateFormat: "dd-mm-yy" }).val();			   
       });
	  function chkamt()
	  {
	  	document.frmtran.balamount.value=document.frmtran.dramount.value-document.frmtran.cramount.value;
	  } 
	function chgd()
	{
	  	//alert(document.frmtran.custid.value);
          
        //var g=document.frmtran.bid.value;
        //  alert(g);
       if(document.frmtran.bid.value > 1)
		{
			document.frmtran.idnumber.disabled = true;
		}
		else
		{
			document.frmtran.idnumber.disabled = false;
		}
          
		var a=document.frmtran.custid.value;
		if(a.substring(0,1)=="i")
		{
			document.frmtran.sid.disabled = false;
		}
		else
		{
			document.frmtran.sid.disabled = true;
		}
		if(a.substring(0,1)=="c")
		{
			document.getElementById('ct').innerHTML="Customer";
		}
		if(a.substring(0,1)=="i")
		{
			document.getElementById('ct').innerHTML="Distributor";
		}
		if(a.substring(0,1)=="d")
		{
			document.getElementById('ct').innerHTML="Agent";
		}
        if(a.substring(0,1)=="r")
    	{
			document.getElementById('ct').innerHTML="Corporate";
		}
        if(a.substring(0,1)=="v")
        {
        	document.getElementById('ct').innerHTML="Vendor";
		}
	}  
</script>

<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Transaction / Modify Transaction</label></td> 

<div  align="center">
	<div  ng-controller="MyCtrl">
	<div align="center">
			<FORM METHOD="post" name="frmtran" action="transactionedit.php">
			<input type="hidden" name="trnid" value="<?=$rowedit['trnid']?>" id="trnid">
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="874" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="6" align="center" height="30" style="text-align:center; color:#FF0000;"><?=$msg?></td></tr>
				<tr><td colspan="6" align="center" height="30" style="text-align:center;font-size:14px; color:#333333; font-weight:bold; ">Transaction Master(Edit)</td></tr>
				<tr bgcolor="#FFFFFF">
				  <td width="149"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Date</label></td>
				  <td width="9"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="272" style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= "" value="<?=$dateist?>" id="datepicker3" name="datepicker3" class="smallInput" />
				  </td>
				  <td colspan="3"><div id="ct" style="color:#669900";"border:thin" ></label></td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Nature Of Business</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="bid" id="bid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							
							$bs='';
							$sqlb="select * from businessmast where status=0 order by bdesc";
							$resb=mysql_query($sqlb);
							while($rowb=mysql_fetch_assoc($resb))
							{
								if ($rowb['bid']==$rowedit['bid'])
									$bs='selected="selected"';
								else
									$bs='';	
						?>
							<option <?=$bs?> value="<?=$rowb['bid']?>"><?=$rowb['bdesc']?></option>
						<?
							}
						?>	
						</select>
					</td>
				  <td width="99" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Sub Category</label></td>
				  <td width="5" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="250"  style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="catid" id="catid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$cs='';
							$sqlc="select * from categorymast where status=0 order by catdesc";
							$resc=mysql_query($sqlc);
							while($rowc=mysql_fetch_assoc($resc))
							{
								if ($rowc['catid']==$rowedit['catid'])
									$cs='selected="selected"';
								else
									$cs='';	

						?>
							<option <?=$cs?> value="<?=$rowc['catid']?>"><?=$rowc['catdesc']?></option>
						<?
							}
						?>	
						</select>
				  </td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Customer Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<p>
						  <select  name="custid" id="custid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" onchange="chgd();">
						    <?
							$sqlct="select * from customermast where status=0 order by custdesc";
							$resct=mysql_query($sqlct);
							while($rowct=mysql_fetch_assoc($resct))
							{
							if($rowct['custtype']=='AGENT')
								$cid='d'.$rowct['custid'];
							if($rowct['custtype']=='CUSTOMER')
								$cid='c'.$rowct['custid'];
							if($rowct['custtype']=='DISTRIBUTOR')
								$cid='i'.$rowct['custid'];
                            if($rowct['custtype']=='CORPORATE')
    							$cid='r'.$rowct['custid'];
                            if($rowct['custtype']=='VENDOR')
        						$cid='v'.$rowct['custid'];

							if ($rowct['custid']==$rowcust['custid'])
									$cids='selected="selected"';
								else
									$cids='';
							//else
								//$cid='c'.$rowct['custid'];
                            
                                //<option> <?=$cids?> value="<?=$rowct[custid]?>"><?=$rowct['custdesc']?></option>
							?>
						<option <?=$cids?> value="<?=$cid?>"><?=$rowct['custdesc']?></option>
					        <?
							}
						?>	
					      </select>
					  </p>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Sub-Agent Name </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="sid" id="sid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$css='';
							$sqlcts="select * from subdealermast where status=0 order by subname";
							$rescts=mysql_query($sqlcts);
							while($rowcts=mysql_fetch_assoc($rescts))
							{
								if ($rowcts['subid']==$rowedit['subid'])
									$css='selected="selected"';
								else
									$css='';	
						?>
							<option <?=$css?> value="<?=$rowcts['subid']?>"><?=$rowcts['subname']?></option>
						<?
							}
						?>	
						</select>
					</td>
				</tr>
                
                 <tr bgcolor="#FFFFFF">
    				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">From Vendor </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						
						
						<select  name="venid" id="venid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >
						<?
							$cs='';
							$sqlc="select * from customermast where status=0 and custtype= 'VENDOR' order by custdesc";
							$resc=mysql_query($sqlc);
							while($rowc=mysql_fetch_assoc($resc))
							{
								if ($rowc['custid']==$rowedit['venid'])
									$cs='selected="selected"';
								else
									$cs='';	

						?>
							<option <?=$cs?> value="<?=$rowc['venid']?>"><?=$rowc['custdesc']?></option>
						<?
							}
						?>	
						</select>
						
						
									</td>
				 <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Net Buy Rate</label></td>
    				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					  <input type="text" id="netrate" name="netrate" class="smallInput" value="<?=$rowedit['netrate']?>" required= "" placeholder="00" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" /></td>
				</tr>
                
                
                
                
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Dr. Amount</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="dramount" value="<?=$rowedit['debitamt']?>" name="dramount" class="smallInput" onchange="chkamt();" required= "" placeholder="00" style="width:80px; text-align:right; font-size:12px; font-weight:bold;" /></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Cr. Amount</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="cramount" name="cramount" class="smallInput" value="<?=$rowedit['creditamt']?>" required= "" onchange="chkamt();" placeholder="00" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" /></td>
				</tr>
<!--				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Balance</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="balamount" name="balamount" class="smallInput" required= "" disabled="disabled" placeholder="00" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" />					
					</td>
				</tr>
-->				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Remarks</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					 <textarea name="remarks" cols="45" rows="2" class="smallInput" id="remarks" style="font-size:12px; text-align:left; font-weight:bold;"><?=$rowedit['remarks']?></textarea>
					</td>
					
					 <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">ID Number</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
				    <input type="text" id="idnumber" name="idnumber" class="smallInput" value="<?=$rowedit['IDNumber']?>"  onblur="chgd();" placeholder="Id Number" style="width:245px; font-size:12px; font-weight:bold;" /></td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Payment Mode</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="payid" id="payid" class="smallInput" style="width:150px; font-size:12px; font-weight:bold;" >
						<?
							$cp='';
							$sqlcp="select * from paymentmast where status=0 order by pdesc";
							$rescp=mysql_query($sqlcp);
							while($rowcp=mysql_fetch_assoc($rescp))
							{
								if ($rowcp['payid']==$rowedit['payid'])
									$cp='selected="selected"';
								else
									$cp='';	
						?>
							<option <?=$cp?> value="<?=$rowcp['payid']?>"><?=$rowcp['pdesc']?></option>
						<?
							}
						?>	
						</select>
					</td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Pay Date</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="paydate" value="<?=$paydate?>" name="paydate" class="smallInput" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Bank Name</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="bankid" id="bankid" class="smallInput" style="width:150px; font-size:12px; font-weight:bold;" >
						<?
							$b='';
							$sqlck="select * from bankmast where status=0 order by bankname";
							$resck=mysql_query($sqlck);
							while($rowck=mysql_fetch_assoc($resck))
							{
								if ($rowck['bankid']==$rowedit['bankid'])
									$b='selected="selected"';
								else
									$b='';	
						?>
							<option <?=$b?> value="<?=$rowck['bankid']?>"><?=$rowck['bankname']?></option>
						<?
							}
						?>	
						</select>
					</td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Branch</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="branch" name="branch" value="<?=$rowedit['branchname']?>" class="smallInput"  placeholder="Branch" style="width:245px; font-size:12px; font-weight:bold;" />					
					</td>
				</tr>
<!--				<tr bgcolor="#FFFFFF">
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Pay Amount</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="amount" name="amount" value="<?//=$date?>" class="smallInput" required= "" placeholder="00" style="width:80px; font-size:12px; text-align:right; font-weight:bold;" />									
					</td>
					<td colspan="3"></td>
				</tr> -->
				<tr>
					<td align="center" colspan="6" style="background-color:#BBE2EE">
						<input type="submit"  name="submit" value="Update" />
					</td>
				</tr>
			</table>
			</FORM>
	</div>
<!--		OR
		</br>
		<strong>Reference No:</strong> </string>
		<input type="text" ng-model="Referenceno"/>	</br>      
		<button ng-click="activateFilter()"> Search </button>   <br/>
			<br/>
-->
</body>
</html>